<template>
  <div class="app-container" :class="[showBusiness==1?'towSearchHeader':'threeSearchHeader']">
    <div class="customContainer">
      <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small">
        <el-form-item>
          <el-select
            filterable
            placeholder="请选择门店"
            v-model="formInline.store_id"
            style="width:300px"
          >
            <el-option v-for="item in storeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            filterable
            placeholder="请选择指标类型"
            style="width:120px"
            v-model="formInline.index_id"
          >
            <el-option v-for="item in indexList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-date-picker
          style="width:120px"
          value-format="yyyy.MM"
          v-model="pickerDate"
          :editable="false"
          :clearable="false"
          type="month"
          size="small"
          :picker-options="pickerOptions"
          placeholder="选择月"
        ></el-date-picker>
        <el-form-item>
          <dj-button size="small" @search="searchClick">
            <template #default>搜索</template>
          </dj-button>
        </el-form-item>
      </el-form>

      <!-- 列表 -->
      <el-table
        v-if="showBusiness==1"
        highlight-current-row
        :data="list"
        v-loading.body="listLoading"
        border
        size="small"
        :row-class-name="tableRowClassName"
      >
        <el-table-column align="center" :render-header="renderHeader">
          <el-table-column
            align="center"
            label="日期"
            width="400"
            prop="date"
            label-class-name="header14px"
            sortable
            sort-by="index"
          ></el-table-column>
          <el-table-column
            align="center"
            label="星期"
            width="400"
            prop="day"
            label-class-name="header14px"
            sortable
            sort-by="sortWeek"
          ></el-table-column>
          <el-table-column align="center" label="营业额目标（元）" label-class-name="header14px">
            <template slot-scope="scope">
              <div>
                <el-input
                  v-if="scope.row.isAmend==2"
                  :placeholder="dis_holder"
                  :disabled="isset_goal==0"
                  :maxlength="inputLength"
                  style="width:300px"
                  :ref="'input'+scope.$index"
                  @keyup.enter.native="nextFocus(scope.$index)"
                  v-model.number="scope.row.income_money"
                ></el-input>
                <div style="height:40px;line-height:40px" v-else>{{scope.row.income_money}}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="实际完成值（元）"
            label-class-name="header14px"
            prop="actual"
          ></el-table-column>
        </el-table-column>
      </el-table>
      <el-table
        v-else
        highlight-current-row
        :data="epList"
        v-loading.body="listLoading"
        border
        size="small"
        :row-class-name="tableRowClassName"
      >
        <el-table-column align="center" :render-header="renderHeader">
          <el-table-column
            align="center"
            label="日期"
            prop="date"
            label-class-name="header14px"
            sortable
            sort-by="index"
          ></el-table-column>
          <el-table-column
            align="center"
            label="星期"
            prop="day"
            label-class-name="header14px"
            sortable
            sort-by="sortWeek"
          ></el-table-column>
          <el-table-column align="center" label="摊位机目标（币）" label-class-name="header14px">
            <template slot-scope="scope">
              <div>
                <el-input
                  v-if="scope.row.isAmend==2"
                  :placeholder="dis_holder"
                  :disabled="isset_goal==0"
                  :maxlength="inputLength"
                  @keyup.enter.native="nextExpenseFocus(scope.$index,'A')"
                  :ref="'inputA'+scope.$index"
                  v-model="scope.row.booth_machine_coins"
                ></el-input>
                <div style="height:40px;line-height:40px" v-else>{{scope.row.booth_machine_coins}}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="毛利润（元）"
            label-class-name="header14px"
            prop="booth_ratio"
          ></el-table-column>
          <el-table-column align="center" label="礼品机目标（币）" label-class-name="header14px">
            <template slot-scope="scope">
              <div>
                <el-input
                  v-if="scope.row.isAmend==2"
                  :placeholder="dis_holder"
                  :disabled="isset_goal==0"
                  :maxlength="inputLength"
                  @keyup.enter.native="nextExpenseFocus(scope.$index,'B')"
                  :ref="'inputB'+scope.$index"
                  v-model="scope.row.gift_machine_coins"
                ></el-input>
                <div style="height:40px;line-height:40px" v-else>{{scope.row.gift_machine_coins}}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="毛利润（元）"
            label-class-name="header14px"
            prop="gift_ratio"
          ></el-table-column>
          <el-table-column align="center" label="彩票机目标（币）" label-class-name="header14px">
            <template slot-scope="scope">
              <div>
                <el-input
                  v-if="scope.row.isAmend==2"
                  :placeholder="dis_holder"
                  :disabled="isset_goal==0"
                  :maxlength="inputLength"
                  @keyup.enter.native="nextExpenseFocus(scope.$index,'C')"
                  :ref="'inputC'+scope.$index"
                  v-model="scope.row.lottery_machine_coins"
                ></el-input>
                <div style="height:40px;line-height:40px" v-else>{{scope.row.lottery_machine_coins}}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="毛利润（元）"
            label-class-name="header14px"
            prop="lottery_ratio"
          ></el-table-column>
          <el-table-column align="center" label="实际完成值（元）" label-class-name="header14px">
            <template slot-scope="scope">
              <el-button type="text" @click="showActual(scope.row)">{{scope.row.actual}}</el-button>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
      <!-- 弹框 -->
      <el-dialog
        :close-on-click-modal="false"
        width="600px"
        title="实际完成值详情"
        :visible.sync="dialogFormVisible"
      >
        <el-table
          highlight-current-row
          :data="dialogData"
          v-loading.body="listLoading"
          border
          size="small"
        >
          <el-table-column align="center" label="摊位机" prop="booth" label-class-name="header14px"></el-table-column>
          <el-table-column align="center" label="礼品机" prop="gift" label-class-name="header14px"></el-table-column>
          <el-table-column align="center" label="彩票机" label-class-name="header14px" prop="lottery"></el-table-column>
        </el-table>
      </el-dialog>
    </div>
    <!-- 自定义底部 -->
    <div class="bottom_box">
      <el-button
        :disabled="isDisabled"
        v-if="amendClick==1"
        class="pull-right"
        style="margin-right:10px"
        type="primary"
        @click="amend(1)"
        size="small"
      >修改</el-button>
      <el-button
        :disabled="isDisabled||isset_goal==0"
        v-else
        class="pull-right"
        style="margin-right:10px"
        type="primary"
        @click="amend(0)"
        size="small"
      >保存</el-button>
    </div>
  </div>
</template>

<script>
import { money, integer1to999999, integer0to999999 } from "@/utils/validate";
import {
  getList,
  getStoreList,
  goalUpdate,
  expenseGoal,
  expenseUpdate,
} from "@/api/operation/indexConfirm";
export default {
  data() {
    return {
      list: [],
      eList: [],
      oldList: [],
      storeList: null,
      listLoading: false,
      isDisabled: false,
      dialogFormVisible: false,
      showBusiness: 1,
      allIncomeMoney: 0,
      isset_goal: 0,
      dis_holder: "",
      allActual: 0,
      amendClick: 1,
      inputLength: 6,
      booth_business_money: 0,
      booth_actual_money: 0,
      gift_business_money: 0,
      gift_actual_money: 0,
      lottery_business_money: 0,
      lottery_actual_money: 0,
      pass_business_money: 0,
      pass_actual_money: 0,
      formInline: {
        store_id: "",
        index_id: 1,
        datetime: "",
        look_del: "0",
      },
      dialogData: [],
      indexList: [
        { id: 1, name: "营业类指标" },
        { id: 0, name: "消费类指标" },
      ],
      pickerDate: new Date(
        Date.UTC(new Date().getFullYear(), new Date().getMonth())
      )
        .toISOString()
        .slice(0, 7)
        .replace("-", ".")
        .replace("-", "."),
      pickerOptions: {
        disabledDate(time) {
          let date = new Date();
          let lastDate = new Date(date.getFullYear(), date.getMonth() + 2, 1);
          return time.getTime() > lastDate - 8.64e7;
        },
      },
    };
  },
  created() {
    this.getStore();
    //this.fetchData();
  },
  methods: {
    //回车下一个输入框获取焦点
    nextFocus(index) {
      for (let i = 1; i < 32; i++) {
        let focusIndex = index + i;
        let inputRef = "input" + focusIndex;
        if (this.$refs[inputRef]) {
          this.$refs[inputRef].$el.children[0].focus();
          return;
        }
      }
    },
    nextExpenseFocus(index, type) {
      for (let i = 1; i < 32; i++) {
        let focusIndex = index + i;
        let inputRef = "input";
        if (type == "A") {
          inputRef += "A" + focusIndex;
        } else if (type == "B") {
          inputRef += "B" + focusIndex;
        } else {
          inputRef += "C" + focusIndex;
        }
        //console.log(inputRef)
        if (this.$refs[inputRef]) {
          this.$refs[inputRef].$el.children[0].focus();
          return;
        }
      }
    },
    //表头
    renderHeader(h, { column }) {
      var that = this;
      if (that.showBusiness == 1) {
        return (
          <div style="font-size:18px;color:#409eff;text-align:center;position:relative;width:1240px">
            <div style="display:flex;justify-content:center;font-size:18px;color:#409eff;position:relative;top:1px;left:0px">
              <div style="width:240px;">
                总营业额目标：{that.allIncomeMoney}
              </div>
              <div style="width:400px;">
                <div
                  style={
                    that.allQuota >= that.allIncomeMoney ? "" : "color:red;"
                  }
                >
                  当前总分配额：{that.allQuota}
                </div>
                <div style="color:red;font-size:14px">
                  {that.allQuota >= that.allIncomeMoney
                    ? ""
                    : "分配额低于总部目标"}
                </div>
              </div>
              <div style="width:240px;">总实际完成值：{that.allActual}</div>
            </div>
          </div>
        );
      } else {
        return (
          <div style="display:flex;justify-content:space-around;font-size:16px;color:#409eff;">
            <div style="width:280px;display:flex;flex-direction: column;">
              <div style="height:30px;text-align:left">
                摊位机毛利润目标：{that.booth_business_money}
              </div>
              <div
                style={
                  that.allBooth >= that.booth_business_money
                    ? "height:30px;text-align:left;color:#50d57f"
                    : "height:30px;text-align:left;color:red;"
                }
              >
                摊位机总分配额：{that.allBooth}
              </div>
              <div style="height:30px;text-align:left;color:#ecb60e">
                摊位机总完成值：{that.booth_actual_money}
              </div>
            </div>
            <div style="width:280px;display:flex;flex-direction: column;">
              <div style="height:30px;text-align:left">
                礼品机毛利润目标：{that.gift_business_money}
              </div>
              <div
                style={
                  that.allGift >= that.gift_business_money
                    ? "height:30px;text-align:left;color:#50d57f"
                    : "height:30px;text-align:left;color:red;"
                }
              >
                礼品机总分配额：{that.allGift}
              </div>
              <div style="height:30px;text-align:left;color:#ecb60e">
                礼品机总完成值：{that.gift_actual_money}
              </div>
            </div>
            <div style="width:280px;display:flex;flex-direction: column;">
              <div style="height:30px;text-align:left">
                彩票机毛利润目标：{that.lottery_business_money}
              </div>
              <div
                style={
                  that.allLottery >= that.lottery_business_money
                    ? "height:30px;text-align:left;color:#50d57f"
                    : "height:30px;text-align:left;color:red;"
                }
              >
                彩票机总分配额：{that.allLottery}
              </div>
              <div style="height:30px;text-align:left;color:#ecb60e">
                彩票机总完成值：{that.lottery_actual_money}
              </div>
            </div>
            <div style="width:280px;display:flex;flex-direction: column;">
              <div style="height:30px;text-align:left">
                门禁类毛利润目标：{that.pass_business_money}
              </div>
              <div style="text-align:left;height:30px;width:100px"></div>
              <div style="height:30px;text-align:left;color:#ecb60e">
                门禁类总完成值：{that.pass_actual_money}
              </div>
            </div>
          </div>
        );
      }
    },
    searchClick() {
      this.fetchData();
    },
    amend(i) {
      if (i == 1) {
        this.amendClick = 0;
        if (this.showBusiness == 1) {
          this.list.forEach((val) => {
            if (val.isAmend == 1) val.isAmend = 2;
          });
        } else {
          this.eList.forEach((val) => {
            if (val.isAmend == 1) val.isAmend = 2;
          });
        }
      } else {
        this.submit();
      }
    },
    // 门店列表获取
    getStore() {
      this.listLoading = true;
      getStoreList({
        look_del: this.formInline.look_del,
        category_id: 403,
      }).then((response) => {
        this.storeList = response;
        let data = response.filter(
          (res) => res.id == this.$store.getters.optionId
        );
        if (data.length > 0) {
          this.formInline.store_id = data[0].id;
        }
        this.fetchData();
      });
    },
    //展示实际完成值
    showActual(row) {
      //console.log(row)
      this.dialogFormVisible = true;
      this.dialogData = [];
      this.dialogData.push({
        booth: row.actual_money.booth_project.toFixed(2),
        gift: row.actual_money.gift_project.toFixed(2),
        lottery: row.actual_money.lottery_project.toFixed(2),
      });
    },
    fetchData() {
      this.listLoading = true;
      //console.log(this.pickerDate);
      let checkMonth = this.pickerDate
        .replace(/\b(0+)/gi, "")
        .replace(/\./, "-");
      let mon = new Date(checkMonth) / 1000;
      let date = new Date();
      let cunMon =
        new Date(date.getFullYear() + "-" + (date.getMonth() + 1)) / 1000;
      if (cunMon > mon) {
        this.isDisabled = true;
      } else {
        this.isDisabled = false;
      }
      //console.log(checkMonth,mon,cunMon);
      this.formInline.datetime =
        this.pickerDate.split(".")[0] +
        "-" +
        parseInt(this.pickerDate.split(".")[1]);
      //console.log(this.formInline)
      this.allActual = 0;
      let weeks = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六",
      ];
      let today = new Date().toLocaleDateString().replace(/\//g, "-");
      today = new Date(today) / 1000;
      let sum = 0;
      if (this.formInline.index_id == 0) {
        this.eList = [];
        expenseGoal({
          store_id: this.formInline.store_id,
          datetime: this.formInline.datetime,
        })
          .then((res) => {
            this.isset_goal = res.isset_goal;
            if (res.isset_goal == 0) {
              this.dis_holder = "总部指标未录入";
            } else {
              this.dis_holder = "";
            }
            this.allIncomeMoney =
              res.booth_machine_money / 1 +
              res.gift_machine_money / 1 +
              res.lottery_machine_money / 1 +
              res.pass_business_money / 1;
            this.booth_business_money = res.booth_machine_money / 1;
            this.gift_business_money = res.gift_machine_money / 1;
            this.lottery_business_money = res.lottery_machine_money / 1;
            this.pass_business_money = res.pass_business_money / 1;
            this.pass_actual_money = (res.pass_actual_money / 1).toFixed(2);
            this.booth_actual_money = 0;
            this.gift_actual_money = 0;
            this.lottery_actual_money = 0;
            res.list.forEach((val, i) => {
              let actual_money = 0;
              if (val.actual_money) {
                actual_money =
                  val.actual_money.booth_project.toFixed(2) / 1 +
                  val.actual_money.gift_project.toFixed(2) / 1 +
                  val.actual_money.lottery_project.toFixed(2) / 1;
                this.booth_actual_money += val.actual_money.booth_project / 1;
                this.gift_actual_money += val.actual_money.gift_project / 1;
                this.lottery_actual_money +=
                  val.actual_money.lottery_project / 1;
              }
              val.actual = actual_money == 0 ? "-" : actual_money.toFixed(2);
              val.day = weeks[val.week];
              val.sortWeek = val.week == 0 ? "7" : val.week;
              val.date = val.datetime.replace(/\b(0+)/gi, "");
              val.isAmend = today >= val.time ? "0" : "1";
              val.booth_machine_coins =
                val.booth_machine_status == 0
                  ? ""
                  : val.booth_machine_coins / 1;
              val.gift_machine_coins =
                val.gift_machine_status == 0 ? "" : val.gift_machine_coins / 1;
              val.lottery_machine_coins =
                val.lottery_machine_status == 0
                  ? ""
                  : val.lottery_machine_coins / 1;
              val.pass_business_coins =
                val.pass_business_status == 0
                  ? ""
                  : val.pass_business_coinsy / 1;
              val.pass_business = res.pass_business_money / 1;
              val.pass_actual = res.pass_actual_money / 1;
              val.booth_ratio = (val.booth_machine_coins * 0.83 * 0.65).toFixed(
                2
              );
              val.gift_ratio = (val.gift_machine_coins * 0.83 * 0.65).toFixed(
                2
              );
              val.lottery_ratio = (
                val.lottery_machine_coins *
                0.83 *
                0.7
              ).toFixed(2);
              sum +=
                val.booth_machine_coins +
                val.gift_machine_coins +
                val.lottery_machine_coins;
              //this.allActual+=actual_money;
              //console.log(today,val.time)
            });
            this.booth_actual_money = this.booth_actual_money.toFixed(2);
            this.gift_actual_money = this.gift_actual_money.toFixed(2);
            this.lottery_actual_money = this.lottery_actual_money.toFixed(2);
            this.oldList = JSON.parse(JSON.stringify(res.list));
            //console.log(this.oldList,this.allActual);
            this.eList = res.list;
            if (sum > 0) {
              this.amendClick = 1;
            } else {
              this.amendClick = 0;
              this.eList.forEach((val) => {
                if (val.isAmend == 1) val.isAmend = 2;
              });
            }
            //console.log(res,this.allIncomeMoney,this.allActual,"sum:"+sum)
            this.showBusiness = 0;
            this.listLoading = false;
          })
          .catch((res) => {
            this.listLoading = false;
          });
      } else {
        this.list = [];
        getList({
          store_id: this.formInline.store_id,
          datetime: this.formInline.datetime,
        })
          .then((res) => {
            //console.log(res)
            this.allIncomeMoney = res.income_money;
            this.isset_goal = res.isset_goal;
            if (res.isset_goal == 0) {
              this.dis_holder = "总部指标未录入";
            } else {
              this.dis_holder = "";
            }
            // let weeks=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
            // let today=(new Date()).toLocaleDateString().replace(/\//g,'-');
            // today=(new Date(today))/1000;
            // let sum=0;
            res.list.forEach((val, i) => {
              val.actual = val.actual_money == 0 ? "-" : val.actual_money;
              val.day = weeks[val.week];
              val.sortWeek = val.week == 0 ? "7" : val.week;
              val.date = val.datetime.replace(/\b(0+)/gi, "");
              val.isAmend = today >= val.time ? "0" : "1";
              sum += val.income_money / 1;
              val.income_money =
                val.income_money_status == 0 ? "" : val.income_money / 1;
              this.allActual += val.actual_money / 1;
            });
            this.allActual = Math.round(this.allActual);
            this.oldList = JSON.parse(JSON.stringify(res.list));
            //console.log(this.oldList);
            this.list = res.list;
            //判断当前月所有指标是否填写过
            if (sum > 0) {
              this.amendClick = 1;
            } else {
              this.amendClick = 0;
              this.list.forEach((val) => {
                if (val.isAmend == 1) val.isAmend = 2;
              });
            }
            this.showBusiness = 1;
            this.listLoading = false;
          })
          .catch((res) => {
            this.listLoading = false;
          });
      }
      //console.log(this.list,this.allQuota)
    },
    submit() {
      this.listLoading = true;
      if (this.showBusiness == 1) {
        if (this.allQuota < this.allIncomeMoney) {
          this.$message.error("当前营业额目标未达标，请重新设置");
          this.listLoading = false;
          return;
        }
        let data = {};
        data.store_id = this.formInline.store_id;
        data.list = [];
        for (let i in this.list) {
          if (
            !integer1to999999(this.list[i].income_money) &&
            this.list[i].isAmend > 0
          ) {
            this.$message.error("营业额目标范围为1-999999的整数，请重新设置");
            this.listLoading = false;
            return;
          }
          if (this.oldList[i].income_money != this.list[i].income_money) {
            data.list.push({
              datetime: this.list[i].time,
              income_money: this.list[i].income_money,
              income_money_status: 1,
            });
            this.oldList[i].income_money = this.list[i].income_money;
          }
        }
        if (data.list.length == 0) {
          this.listLoading = false;
          this.list.forEach((val) => {
            if (val.isAmend == 2) val.isAmend = 1;
          });
          this.amendClick = 1;
          return;
        }
        //console.log(data)
        goalUpdate(data).then((res) => {
          //console.log(res)
          this.$message({
            type: res.code == 1 ? "success" : "error",
            message: res.message,
          });
          this.list.forEach((val) => {
            if (val.isAmend == 2) val.isAmend = 1;
          });
          this.amendClick = 1;
        });
      } else {
        //console.log(this.eList)
        if (this.allBooth < this.booth_business_money) {
          this.$message.error("当前摊位机总分配额未达标，请重新设置");
          this.listLoading = false;
          return;
        }
        if (this.allGift < this.gift_business_money) {
          this.$message.error("当前礼品机总分配额未达标，请重新设置");
          this.listLoading = false;
          return;
        }
        if (this.allLottery < this.lottery_business_money) {
          this.$message.error("当前彩票机总分配额未达标，请重新设置");
          this.listLoading = false;
          return;
        }
        let data = {};
        data.store_id = this.formInline.store_id;
        data.list = [];
        for (let i in this.eList) {
          if (
            this.eList[i].booth_machine_coins &&
            !integer0to999999(this.eList[i].booth_machine_coins) &&
            this.eList[i].isAmend > 0
          ) {
            this.$message.error("摊位机目标范围为0-999999的整数，请重新设置");
            this.listLoading = false;
            return;
          }
          if (
            this.eList[i].gift_machine_coins &&
            !integer0to999999(this.eList[i].gift_machine_coins) &&
            this.eList[i].isAmend > 0
          ) {
            this.$message.error("礼品机目标范围为0-999999的整数，请重新设置");
            this.listLoading = false;
            return;
          }
          if (
            this.eList[i].lottery_machine_coins &&
            !integer0to999999(this.eList[i].lottery_machine_coins) &&
            this.eList[i].isAmend > 0
          ) {
            this.$message.error("彩票机目标范围为0-999999的整数，请重新设置");
            this.listLoading = false;
            return;
          }
          if (
            this.oldList[i].booth_machine_coins !=
              this.eList[i].booth_machine_coins ||
            this.oldList[i].gift_machine_coins !=
              this.eList[i].gift_machine_coins ||
            this.oldList[i].lottery_machine_coins !=
              this.eList[i].lottery_machine_coins
          ) {
            let booth_machine_status =
              this.eList[i].booth_machine_status == 1
                ? "1"
                : this.eList[i].booth_machine_coins === ""
                ? "0"
                : "1";
            let gift_machine_status =
              this.eList[i].gift_machine_status == 1
                ? "1"
                : this.eList[i].gift_machine_coins === ""
                ? "0"
                : "1";
            let lottery_machine_status =
              this.eList[i].lottery_machine_status == 1
                ? "1"
                : this.eList[i].lottery_machine_coins === ""
                ? "0"
                : "1";
            data.list.push({
              datetime: this.eList[i].time,
              booth_machine_coins: this.eList[i].booth_machine_coins,
              gift_machine_coins: this.eList[i].gift_machine_coins,
              lottery_machine_coins: this.eList[i].lottery_machine_coins,
              booth_machine_status,
              gift_machine_status,
              lottery_machine_status,
            });
            this.oldList[i].booth_machine_coins = this.eList[
              i
            ].booth_machine_coins;
            this.oldList[i].gift_machine_coins = this.eList[
              i
            ].gift_machine_coins;
            this.oldList[i].lottery_machine_coins = this.eList[
              i
            ].lottery_machine_coins;
          }
        }
        if (data.list.length == 0) {
          this.listLoading = false;
          this.eList.forEach((val) => {
            if (val.isAmend == 2) val.isAmend = 1;
          });
          this.amendClick = 1;
          return;
        }
        //console.log(data,this.oldList)
        expenseUpdate(data).then((res) => {
          //console.log(res)
          this.$message({
            type: res.code == 1 ? "success" : "error",
            message: res.message,
          });
          this.eList.forEach((val) => {
            if (val.isAmend == 2) val.isAmend = 1;
          });
          this.amendClick = 1;
        });
      }

      this.listLoading = false;
    },
    tableRowClassName({ row, rowIndex }) {
      //console.log(row,rowIndex)
      if (row.day === "星期六" || row.day === "星期日") {
        return "sun-row";
      } else if (row.day === "星期五") {
        return "fri-row";
      }
      return "";
    },
  },
  computed: {
    allQuota: function () {
      if (this.list.length > 0)
        return this.list.reduce(
          (prev, list) =>
            prev +
            (list.income_money && integer1to999999(list.income_money)
              ? parseInt(list.income_money)
              : 0),
          0
        );
      else return 0;
    },
    allBooth: function () {
      if (this.epList.length > 0) {
        let num = this.epList.reduce(
          (prev, list) =>
            prev +
            (list.booth_ratio && money(list.booth_ratio)
              ? Number(list.booth_ratio)
              : 0),
          0
        );
        return num.toFixed(2);
      } else return "0.00";
    },
    allGift: function () {
      if (this.epList.length > 0) {
        let num = this.epList.reduce(
          (prev, list) =>
            prev +
            (list.gift_ratio && money(list.gift_ratio)
              ? Number(list.gift_ratio)
              : 0),
          0
        );
        return num.toFixed(2);
      } else return "0.00";
    },
    allLottery: function () {
      if (this.epList.length > 0) {
        let num = this.epList.reduce(
          (prev, list) =>
            prev +
            (list.lottery_ratio && money(list.lottery_ratio)
              ? Number(list.lottery_ratio)
              : 0),
          0
        );
        return num.toFixed(2);
      } else return "0.00";
    },
    //利用计算属性监听数组中对象属性值的变化
    epList: function () {
      this.eList.forEach((val) => {
        val.booth_ratio = integer1to999999(val.booth_machine_coins)
          ? (val.booth_machine_coins * 0.83 * 0.65).toFixed(2)
          : 0;
        val.gift_ratio = integer1to999999(val.gift_machine_coins)
          ? (val.gift_machine_coins * 0.83 * 0.65).toFixed(2)
          : 0;
        val.lottery_ratio = integer1to999999(val.lottery_machine_coins)
          ? (val.lottery_machine_coins * 0.83 * 0.7).toFixed(2)
          : 0;
      });
      return this.eList;
    },
  },
};
</script>

<style scoped>
.el-table >>> .sun-row {
  /* background: #3282db; */
  color: #ff4b4b;
}
.el-table >>> .fri-row {
  /* background: #ffb03c; */
  color: #ffb03c;
}
</style>

